/**reducer的作用：返回一个新的状态 */
import { FETCH_TEST, ADD_USER, DELETE_USER } from '../constant/types';

const initalState = {
    item : [
        {name: "张三",age: 18}
    ]
}

export default function(state = initalState, action){
    console.log(state,action);
    let payload = action.payload;
    switch(action.type){
        case FETCH_TEST:
            state['item'] = [...state['item'],payload];
            console.log(state);
            return {
                ...state
            }
        case ADD_USER:
            state['item'] = [...state['item'],payload];
            console.log(state);
            return {
                ...state
            }
        case DELETE_USER:
            // state['item'].splice(state['item'].length - 1 ,1);
            state['item'].pop();
            console.log(state);
            state['item'] = [...state['item']];
            return {
                ...state
            }
        default:
            return state;
    }
}